package messages;

import util.AsciiConversions;

public class ParListRsp extends MessageHeader {

	public static final short	PAR_LIST_RSP_ID	= 12;

	private byte				messageCount_actual;
	private byte				messageCount_total;
	private ParListElement[]	parListElements;

	/* ---------------------------------------------------------------- CONSTRUCTORS */

	/**
	 * @param _destID
	 * @param _srcID
	 * @param _messageCount
	 * @param _messageID
	 * @param _asciiID
	 */
	public ParListRsp( short _destID , short _srcID , byte _messageCount_actual ,
			byte _messageCount_total , ParListElement[] _parListElements ) {
		super( _destID , _srcID );
		concatCommandID( PAR_LIST_RSP_ID );
		concatMessageCountActual( _messageCount_actual );
		concatMessageCountTotal( _messageCount_total );
		concatParListElements( _parListElements );
	}

	/* ---------------------------------------------------------------- PRIVATE */

	/**
	 * @param _parListElements
	 */
	private void concatParListElements( ParListElement[] _parListElements ) {
		this.parListElements = _parListElements;
		if ( _parListElements != null )
			this.incrementLength( (short) (_parListElements.length * ParListElement.PAR_LIST_ELEMENT_SIZE ) );
	}

	/**
	 * @param commandID
	 */
	private void concatCommandID( short commandID ) {
		this.incrementLength( (short) 2 );
	}

	/**
	 * @param _messageCount_actual
	 */
	private void concatMessageCountActual( byte _messageCount_actual ) {
		this.messageCount_actual = _messageCount_actual;
		this.incrementLength( (short) 1 );
	}

	/**
	 * @param _messageCount_total
	 */
	private void concatMessageCountTotal( byte _messageCount_total ) {
		this.messageCount_total = _messageCount_total;
		this.incrementLength( (short) 1 );
	}

	/* ---------------------------------------------------------------- PUBLIC */

	public byte getMessageCount_actual( ) {
		return messageCount_actual;
	}

	public void setMessageCount_actual( byte messageCountActual ) {
		messageCount_actual = messageCountActual;
	}

	public byte getMessageCount_total( ) {
		return messageCount_total;
	}

	public void setMessageCount_total( byte messageCountTotal ) {
		messageCount_total = messageCountTotal;
	}

	public ParListElement[] getParListElements( ) {
		return parListElements;
	}

	public void setParListElements( ParListElement[] parListElements ) {
		this.parListElements = parListElements;
	}

	@Override
	public String toString( ) {
		StringBuilder stb = new StringBuilder( );
		stb.append( " [ PAR_LIST_RSP ] = " + super.toString( ) + " | <Command_ID="
				+ PAR_LIST_RSP_ID + "> | <actualMessage=" + this.messageCount_actual
				+ ".totalMessages=" + this.messageCount_total + "> | " );

		if ( this.parListElements == null )
			stb.append( " <null> " );
		else {
			stb.append( " [" );
			for ( ParListElement p : parListElements ) {
				stb.append( "[ <"+p+"> | " );
				stb.append( "<AsciiID=" + AsciiConversions.c16_to_c8( p.getChars( ) ) + "> ]" );
			}
			stb.append( "] " );
		}
		return stb.toString( );
	}

}
